'''from pylab import mpl

mpl.rcParams['font.sans-serif'] = ['STZhongsong']
mpl.rcParams['axes.unicode_minus'] = False

import matplotlib.pyplot as plt
import random
import numpy as np
import xlwt


class Car:

    def _init_(self, length, width):
        self.length = length  # 车长
        self.width = width  # 车宽

    length = 3
    width = 1.6

    # 静态参数
    S = 2  # 静态车间距
    T = 1.6  # 车头时距
    aMax = 0.73  # 最大期望加速度
    bMax = 1.67  # 最大期望减速度
    V0 = 33.3  # m/s
    par = 0.6

    # 更新车间距
    def updateD(self):
        if self.X > self.front.X:
            self.D = self.X - self.front.X + self.front.length - Road.length
        else:
            self.D = self.X - self.front.X + self.front.length

    # 更新速度差
    def updatedV(self):
        self.dV = self.V - self.front.V

    # 更新期望跟驰距离
    def updateD_des(self):
        self.updatedV()
        self.D_des = self.S + self.V * self.T + self.V * self.dV / (2 * (self.aMax * self.bMax) ** 0.5)

    # 更新加速度
    def updateA(self):
        self.updateD()
        self.updateD_des()
        self.A = self.par * (1 - (self.V / self.V0) ** 4 - (self.D_des / self.D) ** 2)

    # 更新速度
    def updateV(self):
        self.updateA()
        self.V = max(self.V + self.A, 0)

    # 更新位置
    def updateX(self):
        self.updateV()
        self.X = (self.X + self.V) % Road.length


class Road:
    def _init_(self, motorPercent, length, width):
        self.motorPercent = motorPercent  # 道路占有率
        self.length = length  # 车道长度
        self.width = width  # 车道宽度

    motorPercent = 0.9
    length = 1000
    width = 3.5

    # 车辆加载
    def initCars(self):
        # 计算车辆数量
        self.numOfCar = (int)(self.length / 3 * self.motorPercent)
        # 生成车辆
        self.ls = []
        gas = (self.length / self.numOfCar)
        for i in range(self.numOfCar):
            c = Car()
            # 等间距放置车辆
            c.X = i * gas
            c.Y = 1
            c.V = 0
            c.index = i
            self.ls.append(c)
            # 新增车辆为上一辆车的前车
            if i > 0:
                c.back = self.ls[self.ls.index(c) - 1]
                c.back.front = c
            # 设置车辆颜色
            c.color = [random.random(), random.random(), random.random()]
        # 头车的前车是尾车
        self.ls[len(self.ls) - 1].front = self.ls[0]
        self.ls[0].back = self.ls[len(self.ls) - 1]
        '''
import matplotlib.pyplot as plt


a_Max = 0.73
b_max = 1.67
v_Max = 60

car_speed = []
for i in range(20):
    car_speed.append(40)
#print(car_speed)

car_D = []
for i in range(20):
    car_D.append([0])
#print(car_D)

car_T = []
for i in range(20):
    car_T.append([2*i])
#print(car_T)

'''1000s'''
for x in range(100):
    for i in range(20):
        if car_T[i][0] <= x :
            car_D[i].append(car_D[i][x] + car_speed[i] * 1 )
            car_T[i].append( 1*(x+1) )
        else:
            car_D[i].append(car_D[i][0])

for i in range(20):
    car_D[i] = sorted(list(set(car_D[i])),key=car_D[i].index)


print(car_T)
print(car_D)

for i in range(20):
    plt.plot(car_T[i],car_D[i])

plt.show()
